﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SMM.TipsForm
{
    public partial class setListForm : Form
    {
        String cargoList = "";
        public setListForm(String name,String str,int sum,String allPrice)
        {
            InitializeComponent();
            label6.Text = "收银员：" + name;
            textBox1.Text = "序号\t商品\t单价\t数量\t小计\r\n"+str;
            label5.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            label3.Text = "总数："+sum;
            label4.Text = "总价：" + allPrice;
            cargoList = "\t普通超市\r\n\t购物小票\r\n收银员：" + name + "\r\n时间："
                + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")+"\r\n"+ textBox1.Text + "\r\n\r\n\r\n总数："+sum+"\t总价："+allPrice
                +"\r\n欢迎下次光临！";
            netBtn.Select();
        }

        private void subBtn_Click(object sender, EventArgs e)
        {

        }

        private void backBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void netBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("网络支付中......", "支付", MessageBoxButtons.OKCancel) == DialogResult.OK){
                //相关支付接口
                printList();
                this.Close();
            }
        }

        private void cashBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("现金支付中......", "支付", MessageBoxButtons.OKCancel) == DialogResult.OK) {
                //弹出现金匣
                printList();
                this.Close();
            }
        }

        private void printList() {
            String fileName = "D:\\"+DateTime.Now.ToString("yyyyMMddhhmmss")+".txt";
            if (!File.Exists(fileName))
            {
                FileStream fs1 = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs1);
                sw.WriteLine(cargoList);//开始写入值
                sw.Close();
                fs1.Close();
            }
            else
            {
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Write);
                StreamWriter sr = new StreamWriter(fs);
                sr.WriteLine(cargoList);//开始写入值
                sr.Close();
                fs.Close();
            }
        }
    }
}
